<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
<title>活动倒计时</title>
<link href="/assets/css/jingang_style.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="/assets/js/jquery-1.9.1.min.js"></script>
</head>

<body>
	<div class="w">
		<div class="bg-box">
			<div class="title">
				<img src="/assets/img/jgimg/title01.png">
			</div>
			<div class="colockbox clearfix" id="demo02">
				<span class="hour">00</span> : <span class="minute">00</span> : <span class="second">00</span>
			</div>
			<div class="information">
				<!--活动信息123-->
			</div>

		</div>
	</div>
<!--ready_box over-->
<script type="text/javascript">
$(function(){
	/*开奖时间*/
	var endTime = "2016/10/07 15:20:00";
	countDown(endTime,null,"span.hour","span.minute","span.second");
	
	/*活动中奖倒计时*/
	function countDown(time,day_elem,hour_elem,minute_elem,second_elem){
		var end_time = new Date(time).getTime(),//月份是实际月份-1
		sys_second = Math.floor((end_time-new Date().getTime())/1000);
		//先判断是否已过了中奖时间
		if(sys_second < 1){
			alert("抽奖已结束");
			return false;
		}
		var timer = setInterval(function(){
			if (sys_second > 0) {
				sys_second -= 1;
				var day = Math.floor((sys_second / 3600) / 24);
				var hour = Math.floor((sys_second / 3600) % 24);
				var minute = Math.floor((sys_second / 60) % 60);
				var second = Math.floor(sys_second % 60);
				//day_elem && $(day_elem).text(day);								//计算天
				var h = parseFloat(day*24)+parseFloat(hour<10?"0"+hour:hour);
				var h = h < 10 ? "0"+h : h;//计算小时
				var m = minute < 10 ? "0"+minute : minute;							//计算分
				var s = second < 10 ? "0"+second : second;							//计算秒
				$(hour_elem).text(h+"");
				$(minute_elem).text(m+"");
				$(second_elem).text(s);
				//倒计时结束执行中奖方法
				if(sys_second < 1){
					okaward();
				}
			} else { 
				clearInterval(timer);
			}
		}, 1000);
	}
	
	/*倒计时结束则显示中奖信息*/
	function okaward(){
		var savetel_url = "/Home/Jgdraw/kaijiang";
		var teldata = {random:Math.random()};
		$.ajax({
			url:savetel_url,
			data:teldata,
			type:"POST",
			dataType:"JSON",
			success:function (data){
				alert(data.count);
			}
		});
	}

});
</script>  
</body>
</html>
